var chatRecordString = '';
var chatRecordList = [];
var headTypeHtml = '';
var tipIndex = '';

layui.use(function(){
    var form = layui.form;
    var layer = layui.layer;
    //知识库开关
    form.on('switch(switch-knowledgeBase)', function(data){
        var elem = data.elem; // 获得 checkbox 原始 DOM 对象
        var checked = elem.checked; // 获得 checkbox 选中状态
        //var value = elem.value; // 获得 checkbox 值
        //var othis = data.othis; // 获得 checkbox 元素被替换后的 jQuery 对象
        if(checked){
            $('#isKnowledgeBase').val('1');
        }else {
            $('#isKnowledgeBase').val('0');
        }
    });
});

//输入框回车发送
document.getElementById("inputPrompt").addEventListener("keydown", function(event) {
    if (event.code === 'Enter') { // 判断按下的键是否为回车键
        event.preventDefault(); // 阻止默认的换行操作

        //var text = this.value; // 获取textarea的值
        //console.log(text); // 输出textarea的内容
        if($('#isSenting').val()=='0'){
            sentQuestion();
        }
    }
});
//设置点赞、点踩弹框
function setPointTip(){
    //点赞点踩按钮提示框设置
    $(".icon-praise-set").mouseover(function() {
        tipIndex = layer.tips($('#praiseTxt').val(), this, {tips: [1, "#51AEFC"],time:0});
    });
    $(".icon-tread-set").mouseover(function() {
        tipIndex = layer.tips($('#treadTxt').val(), this, {tips: [3, "#C1C1C1"],time:0});
    });
    $(".icon-praise-set").mouseout(function() {layer.close(tipIndex);});
    $(".icon-tread-set").mouseout(function() {layer.close(tipIndex);});
}

//设置页面参数信息
function setChatView(eKnowScene,userSetAiName,modelList) {
    $('#sceneId').val(eKnowScene.id);//场景id
    $('#sceneTitle').text(eKnowScene.sceneTitle==null?'':eKnowScene.sceneTitle);//场景标题
    $('#moreRecordTxt').text(eKnowScene.moreRecordTxt==null?'':eKnowScene.moreRecordTxt);//点击更多聊天记录文案
    $('#noMoreRecordTxt').text(eKnowScene.noMoreRecordTxt==null?'':eKnowScene.noMoreRecordTxt);//无更多聊天记录文案

    //场景名称
    $('#sceneName').text(eKnowScene.sceneName);

    //清空会话按钮
    if(eKnowScene.cleanIsOpen=='1'){//清空会话按钮是否开启（0关闭，1开启）
        $('#cleanIsOpen').show();
        $('#cleanTxt').text(eKnowScene.cleanTxt==null?'':eKnowScene.cleanTxt);//清空会话文案
        $('#cleanPrompt').val(eKnowScene.cleanPrompt);
    }else {
        $('#cleanIsOpen').hide();
    }

    //底部输入框
    $("#inputPrompt").attr("placeholder", eKnowScene.inputPrompt==null?'':eKnowScene.inputPrompt);//输入框文案
    $("#inputPrompt").attr("maxlength",eKnowScene.inputMax==null?0:eKnowScene.inputMax);//输入框字数限制
    $("#inputMax").val(eKnowScene.inputMax==null?0:eKnowScene.inputMax);//输入框输入字数限制（0-1000）
    $("#inputMaxTxt").text(eKnowScene.inputMax==null?0:eKnowScene.inputMax);

    //知识库
    if(eKnowScene.knowledgeBaseIsOpen=='1'){//使用知识库问答配置是否开启（0关闭，1开启）
        $('#knowledgeBaseIsOpen').show();
        $('#knowledgeBaseIsTxt').text(eKnowScene.knowledgeBaseIsTxt==null?'':eKnowScene.knowledgeBaseIsTxt);//使用知识库问答选项的文案
    }else {
        $('#knowledgeBaseIsOpen').hide();
    }
    $('#isKnowledgeBase').val('1');//默认开启使用知识库问答

    //ai角色名相关
    var mdelDefaultName = eKnowScene.modelDefaultName==null?'':eKnowScene.modelDefaultName;//AI默认角色名
    if(eKnowScene.modelRoleIsOpen=='1'){//用户自定义AI角色名是否开启（0关闭，1开启）
        $('#modelRoleIsOpen').show();
        $('#modelRoleTxt').text(eKnowScene.modelRoleTxt==null?'':eKnowScene.modelRoleTxt);//用户自定义AI角色名选项的文案
        //用户是否有自定义角色名
        mdelDefaultName = userSetAiName==null||userSetAiName==''?mdelDefaultName:userSetAiName;
        $('#userSetAiName').val(mdelDefaultName);
    }else {
        $('#modelRoleIsOpen').hide();
        $('#mdelDefaultName').val(mdelDefaultName);
    }
    $('#modelRoleIsOpenVal').val(eKnowScene.modelRoleIsOpen);

    //头像相关
    if(eKnowScene.headType=='0') {//头像类型（0文字加纯色背景、1图片）
        var headTypeTxt = ((userSetAiName==null||userSetAiName=='')?eKnowScene.modelDefaultName:userSetAiName);
        headTypeHtml = '<div class="layui-anim head-txt" style="background-color: '+eKnowScene.headColor+';">'+headTypeTxt+'</div>';
    }else {//图片
        headTypeHtml = '<img class="head-imge-AI" src="'+eKnowScene.headImagePath+'">';
    }
    $('#headType').val(eKnowScene.headType);
    $('#headColor').val(eKnowScene.headColor);
    $('#headImagePath').val(eKnowScene.headImagePath);

    //次数限制
    $('#userChatTimes').val(eKnowScene.userChatTimes);//用户每日问答次数限制
    $('#userChatOverPrompt').val(eKnowScene.userChatOverPrompt);//用户到达次数限制时的提示文案

    //评价
    $('#praiseTxt').val(eKnowScene.praiseTxt);//点赞按钮提示文案
    $('#treadTxt').val(eKnowScene.treadTxt);//点踩按钮提示文案
    $('#evaluateBack').val(eKnowScene.evaluateBack);//评价反馈文案
    $('#evaluateError').val(eKnowScene.evaluateError==null?'':eKnowScene.evaluateError);//评价反馈失败提示语

    //开场白设置
    var prologue = eKnowScene.prologue==null||eKnowScene.prologue==''?'':eKnowScene.prologue;
    if(prologue!='' && prologue.indexOf("*")!=-1){
        $('#prologue').val(prologue.replace("*",mdelDefaultName));//开场白设置
    }else {
        $('#prologue').val(prologue);//开场白设置
    }
    $('#prologueOriginal').val(eKnowScene.prologue);//开场白设置

    //模型无法回答时的提示语
    var sorryTxt = eKnowScene.sorryTxt==null||eKnowScene.sorryTxt==''?'':eKnowScene.sorryTxt;
    if(sorryTxt!='' && sorryTxt.indexOf("*")!=-1){
        $('#sorryTxt').val(sorryTxt.replace("*",mdelDefaultName));//模型无法回答时的提示语
    }else {
        $('#sorryTxt').val(sorryTxt);//模型无法回答时的提示语
    }
    $('#sorryTxtOriginal').val(eKnowScene.sorryTxt);//模型无法回答时的提示语设置


    //点赞点踩按钮提示框设置
    setPointTip();

    //问题模版配置
    var questionTemplateIsOpen = eKnowScene.questionTemplateIsOpen;//问题模版是否开启（0否，1是）
    if(questionTemplateIsOpen=='0'){
        $("#questionTemplateIsOpen").hide();
    }else {
        $("#questionTemplateIsOpen").show();
        var questionTemplateTxt = eKnowScene.questionTemplateTxt;//问题模版文案
        $("#questionTemplateTxt").text(questionTemplateTxt);
    }

    //选择模型
    $("#aiModelTxt").text(eKnowScene.aiModelTxt);
    //选择场景文案
    $("#selectSceneTxt").text(eKnowScene.selectSceneTxt);

    //选择ai模型下拉框
    if(modelList!=null && modelList.length>0){
        $('#chooseModel').html('');
        var htmlStr = '<select name="chooseAiModel" id="chooseAiModel" lay-filter="chooseAiModel">';
        for(var i=0;i<modelList.length;i++){
            if(i==0){
                htmlStr+='<option value="'+modelList[i].id+'" selected>'+modelList[i].modelOwnName+'</option>';
                $('#aiModelId').val(modelList[i].id);
            }else {
                htmlStr+='<option value="'+modelList[i].id+'" >'+modelList[i].modelOwnName+'</option>';
            }
        }
        htmlStr+= '</select>';
        $('#chooseModel').html(htmlStr);
        //选择所属分类
        layui.form.render('select');
    }


}

layui.use(function(){
    var form = layui.form;
    var layer = layui.layer;
    //选择ai模型
    form.on('select(chooseAiModel)', function(data){
        var elem = data.elem; // 获得 select 原始 DOM 对象
        var value = data.value; // 获得被选中的值
        //var othis = data.othis; // 获得 select 元素被替换后的 jQuery 对象
        $('#aiModelId').val(value);
    });
});

//发送按钮
function sentQuestion(){
    var question = $('#inputPrompt').val();
    if(question==null || question==''){
        layer.msg('请输入您要问的问题', {icon: 1});
        return;
    }
    //参数验证
    if(!checkSaveSet()){
        return;
    }

    //动画
    var animStr = 'layui-anim-upbit';
    $('#isSenting').val('1');

    var sentHtml = '<button class="send-btn" onclick="sentQuestion()"></button>';
    $('#sentBtn').html('<button class="send-btn-loading"><i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop icon-loading-btn-set"></i></button>');

    reSetPrologue();
    //用户对话
    var aiTalkHtml =  '<div class="layui-row user-chat">' +
        '<div class="layui-col-xs1" ><div style="width: 100%;height: 1px;"></div></div>' +
        '<div class="layui-col-xs10"><div class="user-content layui-anim '+animStr+'"><span>'+$('#inputPrompt').val()+'</span></div></div>' +
        '<div class="layui-col-xs1">' +
        '   <div class="grid-demo grid-demo-bg1 layui-anim '+animStr+'"><img class="head-imge" src="https://file.mini-ease.com/upload/nomodule/202311/02/230311820.png"></div>' +
        '</div></div>';
    //新增用户对话
    $('#chat_view').append(aiTalkHtml);
    scrollDown();

    //ai无法回答时的
    var aiTalkHtmlSorry =  '<div class="layui-row ai-chat">' +
        '            <div class="layui-col-xs1"><div class="grid-demo grid-demo-bg1 layui-anim '+animStr+'">' +headTypeHtml+ '</div></div>' +
        '            <div class="layui-col-xs10"><div class="ai-content layui-anim '+animStr+'"><span>'+$('#sorryTxt').val()+'</span></div></div>' +
        '            <div class="layui-col-xs1" style="width: 100%;"></div>' +
        '        </div>';

    var chatMessages = JSON.stringify(chatRecordList);//转字符串

    var knowledgeBaseIds = '';
    for(var i=0;i<chooseLedgeBaseList.length;i++){
        if(knowledgeBaseIds==''){
            knowledgeBaseIds = chooseLedgeBaseList[i].id;
        }else {
            knowledgeBaseIds += ','+chooseLedgeBaseList[i].id;
        }
    }
    //清空调试信息
    $('#chatWholeSendMsgInfo').text('');
    $('#chatAnswerInfo').text('');
    $('#chatLedgeBackView').hide();
    $.ajax({
        url: '/api/inter/eKnowChatSetController/getAiChatByTest',
        data: {
            'sceneId':$('#sceneId').val(),
            'isKnowledgeBase':$('#isKnowledgeBase').val(),
            'chatMessages':chatMessages,
            'question':question,
            'userSetAiName':(eKnowSceneInfo.modelDefaultName=='0'?$('#modelDefaultNameSet').val():$('#userSetAiName').val()),
            'modelDefaultName':eKnowSceneInfo.modelDefaultName,
            'aiSystem':$('#aiSystemSet').val(),
            'knowledgeBaseIsOpen':eKnowSceneInfo.knowledgeBaseIsOpen,
            'modelRoleIsOpen':eKnowSceneInfo.modelRoleIsOpen,
            'noLedgePromptKeyValue':returnValueIsNull($('#noPromptSet').val()),
            'noLedgePromptKeyName':'userPrompt',
            'withLedgePromptKeyValue':returnValueIsNull($('#withPromptSet').val()),
            'withLedgePromptKeyName':'other',
            'embeddingBackCount':eKnowSceneInfo.embeddingBackCount,
            'embeddingBackSource':eKnowSceneInfo.embeddingBackSource,
            'knowledgeBaseIds':knowledgeBaseIds,
            'aiModelId':$('#aiModelId').val()
        },
        type: 'POST',
        async: true,
        success: function (result) {
            console.log('发送按钮result:',result);
            $('#sentBtn').html(sentHtml);
            if(result.code=='SUCCESS'){
                //评价相关
                var evaluateHtml = '<a onclick="setEvaluate(\''+result.chatId+'\',\''+result.baiDuChatId+'\',1)"><i class="layui-icon layui-icon-praise icon-praise-set"></i></a>'+
                    '<a onclick="setEvaluate(\''+result.chatId+'\',\''+result.baiDuChatId+'\',0)"><i class="layui-icon layui-icon-tread icon-tread-set"></i></a>';
                var aiTalkHtmlByAi =  '<div class="layui-row ai-chat">' +
                    '            <div class="layui-col-xs1"><div class="grid-demo grid-demo-bg1 layui-anim '+animStr+'">' +headTypeHtml+ '</div></div>' +
                    '            <div class="layui-col-xs10"><div class="ai-content layui-anim '+animStr+'"><span style="white-space: pre-line;">'+result.answer+'</span></div><div class="evaluate-view" id="'+'evaluateView'+result.baiDuChatId+'">'+evaluateHtml+'</div></div>' +
                    '            <div class="layui-col-xs1" style="width: 100%;"></div>' +
                    '        </div>';
                $('#chat_view').append(aiTalkHtmlByAi);
                $('#inputPrompt').val('');//输入框置空
                document.getElementById('textCount').innerHTML = 0;
                chatRecordList.push({"role":"user","content":question});
                chatRecordList.push({"role":"assistant","content":result.answer});
            }else if(result.code=='OVERTIMES'){//当日会话超出限制
                layer.msg($('#userChatOverPrompt').val(), {icon: 2});
            }
            else {
                $('#chat_view').append(aiTalkHtmlSorry);
            }
            scrollDown();
            $('#isSenting').val('0');
            //调试信息设置
            var getSceneKnowledgeList = result.getSceneKnowledgeList;
            if($('#isKnowledgeBase').val()=='1' && getSceneKnowledgeList!=undefined && getSceneKnowledgeList!=null){//开启知识库问答
                $('#chatLedgeBackView').show();

                var shardIdList = result.shardIdList;
                var chatLedgeBackInfoStr = '';
                for(var i=0;i<shardIdList.length;i++){
                    for(var j=0;j<getSceneKnowledgeList.length;j++){
                        if(shardIdList[i].id==getSceneKnowledgeList[j].eSId){
                            chatLedgeBackInfoStr +='<span style="color: #2468F2;line-height: 20px;">(来自：'+getSceneKnowledgeList[j].knowledgeBaseName+'；置信度：'+shardIdList[i].score+')</span>\n';
                            chatLedgeBackInfoStr +=getSceneKnowledgeList[j].information+'\n\n';
                        }
                    }
                }
                $('#chatLedgeBackInfo').html(chatLedgeBackInfoStr);
            }else {
                $('#chatLedgeBackView').hide();
            }
            var wholeSendMsg = result.wholeSendMsg;
            var answer = result.answer;
            $('#chatWholeSendMsgInfo').text(wholeSendMsg);
            $('#chatAnswerInfo').text(answer);
            //点赞点踩按钮提示框设置
            setPointTip();
        },
        error: function () {
            $('#sentBtn').html(sentHtml);
            $('#chat_view').append(aiTalkHtmlSorry);
            scrollDown();
            $('#isSenting').val('0');
        }
    });

}




//页面滚动到底部
function scrollDown() {
    var div = document.getElementById('chat_page');
    div.scrollTop = div.scrollHeight;
}


//点击加载更多
function getMoreRecord(){
    //加载
    $('#moreRecordBtn').hide();
    $('#noMoreRecordTxt').hide();
    $('#moreRecordLoading').show();
    $.ajax({
        url: '/api/inter/eKnowAi/getMoreChatRecord',
        data: {'beginRow':$('#beginRow').val()},
        type: 'POST',
        async: true,
        success: function (result) {
            layer.close();
            console.log('点击加载更多result:',result);
            if(result.code=='SUCCESS'){
                $('#beginRow').val(result.beginRow);
                var chatRecord = result.chatRecord;
                var aiTalkHtml = '';

                var animStr = 'layui-anim-downbit';

                if(chatRecord!=null && chatRecord.length>0){
                    for(var i=0;i<chatRecord.length;i++){
                        //role角色（user，assistant），content内容，evaluate评价(role是user时为-1，-1也表示未评价)，chatId会话id(role是user时为-1)
                        if(chatRecord[i].role=='user'){
                            aiTalkHtml +=  '<div class="layui-row user-chat">\n' +
                                '<div class="layui-col-xs1 "><div style="width: 100%;height: 1px;"></div></div>\n' +
                                '<div class="layui-col-xs10"><div class="user-content layui-anim '+animStr+'"><span style="white-space: pre-line;">'+chatRecord[i].content+'</span></div></div>\n' +
                                '<div class="layui-col-xs1">\n' +
                                '   <div class="grid-demo grid-demo-bg1 layui-anim '+animStr+'"><img class="head-imge" src="https://file.mini-ease.com/upload/nomodule/202311/02/230311820.png"></div>\n' +
                                '</div>\n' +
                                '</div>'
                        }else {
                            //评价相关
                            var evaluateHtml = '';
                            if(chatRecord[i].evaluate=='-1'){
                                evaluateHtml = '<a onclick="setEvaluate(\''+chatRecord[i].chatId+'\',\''+chatRecord[i].baiDuChatId+'\',1)"><i class="layui-icon layui-icon-praise icon-praise-set"></i></a>'+
                                    '<a onclick="setEvaluate(\''+chatRecord[i].chatId+'\',\''+chatRecord[i].baiDuChatId+'\',0)"><i class="layui-icon layui-icon-tread icon-tread-set"></i></a>';
                            }else {
                                if(chatRecord[i].evaluate=='0'){//点踩
                                    evaluateHtml = '<i class="layui-icon layui-icon-tread icon-tread-hasset"></i>';
                                }else{//点赞
                                    evaluateHtml = '<i class="layui-icon layui-icon-praise icon-praise-hasset"></i>';
                                }
                            }
                            aiTalkHtml +=  '<div class="layui-row ai-chat">' +
                                '            <div class="layui-col-xs1"><div class="grid-demo grid-demo-bg1  layui-anim '+animStr+'">' +headTypeHtml+ '</div></div>' +
                                '            <div class="layui-col-xs10"><div class="ai-content  layui-anim '+animStr+'"><span>'+chatRecord[i].content+'</span></div><div class="evaluate-view" id="'+'evaluateView'+chatRecord[i].baiDuChatId+'">'+evaluateHtml+'</div></div>' +
                                '            <div class="layui-col-xs1" style="width: 100%;"></div>' +
                                '        </div>';
                        }

                    }
                    $('#chat_view').prepend(aiTalkHtml);
                    layui.use(function() {
                        var $ = layui.$;
                        var elem = $('#chat_view');
                        elem.removeClass("layui-anim-scale");
                        setTimeout(function(){
                            elem.addClass("layui-anim-scale"); // 给目标元素追加的动画
                        });
                    })

                    if(chatRecord.length>=10){
                        $('#moreRecordBtn').show();
                        $('#noMoreRecordTxt').hide();
                    }else {
                        $('#moreRecordBtn').hide();
                        $('#noMoreRecordTxt').show();
                    }
                    $('#moreRecordLoading').hide();
                }else {
                    $('#moreRecordLoading').hide();
                    $('#moreRecordBtn').hide();
                    $('#noMoreRecordTxt').show();
                }


            }else if(result.code=='NOMORE'){
                $('#moreRecordLoading').hide();
                $('#moreRecordBtn').hide();
                $('#noMoreRecordTxt').show();
            }
            else {
                layer.msg('加载失败，请稍后再试', {icon: 2});
                $('#moreRecordLoading').hide();
                $('#moreRecordBtn').show();
                $('#noMoreRecordTxt').hide();
            }
        },
        error: function () {
            layer.close();
            layer.msg('加载失败，请稍后再试', {icon: 2});
            $('#moreRecordLoading').hide();
            $('#moreRecordBtn').show();
            $('#noMoreRecordTxt').hide();
        }
    });

}

//清空会话
function cleanChatRecord(){
    layer.confirm($('#cleanPrompt').val(), {icon: 3}, function () {
        //点击确定的回调
        layer.msg('请稍后', {
            icon: 16,
            shade: 0.01
        });
        cleanChatRecordYes();
    }, function () {});//点击取消的回调
}
//确认清空会话
function cleanChatRecordYes() {
    chatRecordList = [];
    reSetPrologue();

    var aiTalkHtml = '<div class="layui-row ai-chat">\n' +
        '            <div class="layui-col-xs1"><div class="grid-demo grid-demo-bg1">' +headTypeHtml+ '</div></div>\n' +
        '            <div class="layui-col-xs10"><div class="ai-content"><span>'+$('#prologue').val()+'</span></div></div>\n' +
        '            <div class="layui-col-xs1" style="width: 100%;"></div>\n' +
        '        </div>';
    $('#chat_view').html(aiTalkHtml);
    $('#noMoreRecordTxt').show();
    $('#moreRecordBtn').hide();
    layer.closeAll();

}

//评价按钮
function setEvaluate(chatId,baiDuChatId,evaluate) {
    layer.close(tipIndex);
    var evaluateHtml = '<a onclick="setEvaluate(\''+chatId+'\',\''+baiDuChatId+'\',1)"><i class="layui-icon layui-icon-praise icon-praise-set"></i></a>'+
        '<a onclick="setEvaluate(\''+chatId+'\',\''+baiDuChatId+'\',0)"><i class="layui-icon layui-icon-tread icon-tread-set"></i></a>';

    $('#evaluateView'+baiDuChatId).html('<i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop icon-loading-set"></i>');

    layui.layer.msg($('#evaluateBack').val(), {icon: 1}, function(){});
    if(evaluate=='0'){//点踩
        $('#evaluateView'+baiDuChatId).html('<i class="layui-icon layui-icon-tread icon-tread-hasset"></i>');
    }else{//点赞
        $('#evaluateView'+baiDuChatId).html('<i class="layui-icon layui-icon-praise icon-praise-hasset"></i>');
    }
}

//重新设置与模型名称关联的文案
function reSetPrologue() {
    //头像相关
    if( $('#headType').val()=='0') {//头像类型（0文字加纯色背景、1图片） headColor headImagePath
        var headTypeTxt = ($('#modelRoleIsOpenVal').val()=='0'?$('#mdelDefaultName').val():$('#userSetAiName').val());
        headTypeHtml = '<div class="layui-anim head-txt" style="background-color: '+$('#headColor').val()+';">'+headTypeTxt+'</div>';
    }else {//图片
        headTypeHtml = '<img class="head-imge-AI" src="'+$('#headImagePath').val()+'">';
    }

    //ai角色名相关
    var mdelDefaultName = $('#mdelDefaultName').val();//AI默认角色名
    if($('#modelRoleIsOpenVal').val()=='1') {//用户自定义AI角色名是否开启（0关闭，1开启）
        mdelDefaultName = $('#userSetAiName').val();
    }

    userSetAiName
    //开场白设置
    var prologue = $('#prologueOriginal').val();
    if(prologue!='' && prologue.indexOf("*")!=-1){
        $('#prologue').val(prologue.replace("*",mdelDefaultName));//开场白设置
    }else {
        $('#prologue').val(prologue);//开场白设置
    }

    //模型无法回答时的提示语
    var sorryTxt = $('#sorryTxtOriginal').val();
    if(sorryTxt!='' && sorryTxt.indexOf("*")!=-1){
        $('#sorryTxt').val(sorryTxt.replace("*",mdelDefaultName));//模型无法回答时的提示语
    }else {
        $('#sorryTxt').val(sorryTxt);//模型无法回答时的提示语
    }
}



//聊天页面初始滚动到最底部
var div = document.getElementById('chat_page');
div.scrollTop = div.scrollHeight;

//模型名称变化监听
var userSetAiNameEl = document.getElementById('userSetAiName');
userSetAiNameEl.addEventListener('input',function () {
    setAiModelName();
});


//输入框底下的字数变化监听
var el = document.getElementById('inputPrompt');
el.addEventListener('input',function () {
    var len =  txtCount(this); //   调用函数
    document.getElementById('textCount').innerHTML = len;
});

//函数 - 获取文本内容和长度
function txtCount(el) {
    var val = el.value;
    var eLen = val.length;
    return eLen;
}

//修改模型名
function setAiModelName() {

}
